package com.design;

/**
 * 订单
 */
public class Order {
    private OrderState orderState;
    private String orderId;

    public Order(String orderId){
        this.orderId = orderId;
        this.orderState = new WaitPayOrder();
        System.out.println("订单" + orderId + "创建成功，当前状态为：" + orderState.getStateName());
    }

    public void pay(){
        System.out.println("操作：支付");
        orderState.pay(this);
    }

    public void cancel(){
        System.out.println("操作：取消");
        orderState.cancel(this);
    }

    public void ship(){
        System.out.println("操作：发货");
        orderState.ship(this);
    }

    public void receive(){
        System.out.println("操作：收货");
        orderState.receive(this);
    }

    public void setOrderState(OrderState orderState){
        this.orderState = orderState;
        System.out.println("订单" + orderId + "状态变更为：" + orderState.getStateName());
    }

    public OrderState getOrderState(){
        return orderState;
    }
}
